%GLOBAL CWD; %LET CWD = %SUBSTR(%SYSGET(SAS_EXECFILEPATH), 1, %EVAL(%LENGTH(%SYSGET(SAS_EXECFILEPATH)) - %LENGTH(%SYSGET(SAS_EXECFILENAME)) - 1));
%INCLUDE "&CWD\TOOLS.SAS";

/* SET ELI & CLUSTER */
%LET ELI = FD021;
%LET CLUSTER = 01;

/* IDENTIFYING HANDLE */
%LET COM = &ELI._&CLUSTER.;

/* ITEM-SPECIFIC RIGHT HAND SIDE VARIABLES */
%LET RHS = 
    A1 A2 A3 A4 A5 A6 B1 B2 D1 D2
    D3 D4 D5 D6 E1 E2 F1 H1  
    BRAND_A BRAND_B BRAND_C BRAND_D BRAND_E BRAND_G BRAND_H BRAND_K BRAND_M
    BRAND_R BRAND_S BRAND_T BRAND_W BRAND_AA BRAND_BB BRAND_DD BRAND_EE SPIRAL
    SHANK HONEY TRIM WATER MNAMT MNAMTSQ
    ;

%LET STYR = 0201;
%LET FIRSTPER = 20&STYR.;
%LET LASTPER = 200709;
%LET STDUM = D&STYR.;
%LET RHYRS = D0202 -- D0709;

%LET NSPER = %COUNTMONTHS(&FIRSTPER, &LASTPER);
%LET NVEC = %EVAL(&NSPER + %COUNTWORDS(&RHS));

/* DEFINE ITEM-SPECIFIC PRICE EDITS */
%MACRO EDITS;   
    IF .03 > FULLSAMP_EFFPR_WOTX OR FULLSAMP_EFFPR_WOTX > 1 THEN DELETE;
%MEND;

/* DEFINE ITEM-SPECIFIC DUMMIES */
%MACRO VARS;
    
    A1=(A="A1"); A2=(A="A2"); A3=(A="A3"); A4=(A="A4"); 
    A5=(A="A5"); A6=(A="A6");
    A99SP=(A="A99"); 
    ARRAY AARRAY (7) A1-A6 A99SP;
        DO COUNT=1 TO 7;
        IF A="" THEN AARRAY(COUNT)=.;
    END;

    B1=(B="B1"); B2=(B="B2"); B3=(B="B3");
    ARRAY BARRAY (3) B1-B3;
        DO COUNT=1 TO 3;
        IF B="" THEN BARRAY(COUNT)=.;
    END;

    D1=(D="D1"); D2=(D="D2"); D3=(D="D3"); D4=(D="D4"); D5=(D="D5");
    D6=(D="D6");
    D99SP=(D="D99");
    ARRAY DARRAY (7) D1-D6 D99SP;
        DO COUNT=1 TO 7;
        IF D="" THEN DARRAY(COUNT)=.;
    END;

    E1=(E="E1"); E2=(E="E2"); 
    E99SP=(E="E99"); 
    ARRAY EARRAY (3) E1-E2 E99SP;
        DO COUNT=1 TO 3;
        IF E="" THEN EARRAY(COUNT)=.;
    END;

    F1=(F="F1"); F2=(F="F2"); 
    ARRAY FARRAY (2) F1-F2;
        DO COUNT=1 TO 2;
        IF F="" THEN FARRAY(COUNT)=.;
    END;

    H1=(H="H1");
    H99SP=(H="H99");
    ARRAY HARRAY (2) H1 H99SP;
        DO COUNT=1 TO 2;
        IF H="" THEN HARRAY(COUNT)=.;
    END;

    IF FIND(G99,'**********','I') THEN BRAND_A=1; ELSE BRAND_A=0;
    IF FIND(G99,'**********','I') THEN BRAND_B=1; ELSE BRAND_B=0;
    IF FIND(G99,'**********','I') THEN BRAND_C=1; ELSE BRAND_C=0;
    IF FIND(G99,'**********','I') THEN BRAND_D=1; ELSE BRAND_D=0;
    IF FIND(G99,'**********','I') THEN BRAND_E=1; ELSE BRAND_E=0;
    IF FIND(G99,'**********','I') THEN BRAND_G=1; ELSE BRAND_G=0;
    IF FIND(G99,'**********','I') THEN BRAND_H=1; ELSE BRAND_H=0;
    IF FIND(G99,'**********','I') THEN BRAND_K=1; ELSE BRAND_K=0;
    IF FIND(G99,'**********','I') THEN BRAND_M=1; ELSE BRAND_M=0;
    IF FIND(G99,'**********','I') THEN BRAND_R=1; ELSE BRAND_R=0;
    IF FIND(G99,'**********','I') THEN BRAND_S=1; ELSE BRAND_S=0;
    IF FIND(G99,'**********','I') THEN BRAND_T=1; ELSE BRAND_T=0;
    IF FIND(G99,'**********','I') THEN BRAND_W=1; ELSE BRAND_W=0;
    IF FIND(G99,'**********','I') THEN BRAND_AA=1; ELSE BRAND_AA=0;
    IF FIND(G99,'**********','I') THEN BRAND_BB=1; ELSE BRAND_BB=0;
    IF FIND(G99,'**********','I') THEN BRAND_DD=1; ELSE BRAND_DD=0;
    IF FIND(G99,'**********','I') THEN BRAND_EE=1; ELSE BRAND_EE=0;

    IF FIND(I99,'**********','I') THEN SPIRAL=1;ELSE SPIRAL=0;
    IF FIND(I99,'**********','I') THEN SHANK=1;ELSE SHANK=0;
    IF FIND(I99,'**********','I') THEN HONEY=1;ELSE HONEY=0;
    IF FIND(I99,'**********','I') THEN TRIM=1;ELSE TRIM=0;
    IF FIND(I99,'**********','I') THEN WATER=1;ELSE WATER=0;



    *ELIMINATE QUOTES WITH MISSING SPEC VARIABLES;
    *INCLUDE APPROPRIATE LIST OF SPEC VARIABLES HERE AND ELSEWHERE;
    *MODIFY SIZE OF SPECARRAY AS NEEDED TO NUMBER OF YOUR SPEC VARIABLES PLUS 5;
    *;
    ARRAY SPECARRAY (*) A1 A2 A3 A4 A5 A6 A99SP B1 B2 B3 D1 D2 D3 D4 D5 D6 D99SP
    E1 E2 E99SP F1 F2 H1 H99SP BRAND_A BRAND_B BRAND_C BRAND_D BRAND_E BRAND_G
    BRAND_H BRAND_K BRAND_M BRAND_R BRAND_S BRAND_T BRAND_W BRAND_AA BRAND_BB
    BRAND_DD BRAND_EE SPIRAL SHANK HONEY TRIM WATER DISCDEP--OTHSTORE
    ;
    DO COUNT = 1 TO DIM(SPECARRAY);
        IF SPECARRAY(COUNT)=. THEN DELETE;
    END;
%MEND;

LIBNAME IN "&CWD\DATA";
LIBNAME OUT "&CWD\DATA";

FILENAME OUTLOGS "&CWD\OUTPUT\LOGINDEXES.XLS";
FILENAME OUTCONTS "&CWD\OUTPUT\LOGCONTRIBS.XLS";
FILENAME OUTDISCS "&CWD\OUTPUT\DISCOUNTS.XLS";
FILENAME OUTPCTLS "&CWD\OUTPUT\PCTLS.XLS";

%INCLUDE "&CWD\TABLESTOBUILD.SAS";
